package com.zjb.accountManager.controllers;

import java.util.Date;

import com.jfinal.core.Controller;
import com.zjb.accountManager.beans.model.User;

public class Cp0000 extends Controller {
	
	public void index () {
		this.renderJsp("cp0000.jsp");
	}
	
	public void checkUserName() {
		String account = this.getPara("account");
		
		User user = User.dao.findAccount(account);
			
		this.renderJson(user == null);
	}
	
	
	public void register() {
		String account = this.getPara("account");
		String password = this.getPara("password");
		
		User user = User.dao.findAccount(account);
		
		if (user != null) {
			this.renderJson(false);
			return;
		}
		
		Date createTime = new Date();
		Boolean result = User.dao.register(account, password, createTime);
		this.renderJson(result);
	}
	
	public void login() {
		String account = this.getPara("account");
		String password = this.getPara("password");
		
		Boolean result;
		User user = User.dao.findLoginedAccount(account, password);
		
		if(user == null) {	
			result = false;
		} else {
			this.setSessionAttr("account", account);
			result = true;
		}
		
		renderJson(result);
	}
}
